package main

import (
	"fmt"
	"strconv"
	"time"
)

// time.Sleep(time.Second)
func main() {
	testSleep()
	testUnix()
	countTime()
}

// testSleep
//
//	@Description:  func Sleep(d Duration)
func testSleep() {
	fmt.Println("-------------Sleep-------------")

	for i := 1; i < 10; i++ {
		fmt.Println(time.Now())
		//睡眠 1s
		time.Sleep(time.Second)
		//睡眠 0.1s
		time.Sleep(time.Millisecond * 100)
	}

}

// testUnix
//
//	@Description: 时间戳
func testUnix() {
	fmt.Println("-------------获取时间戳-------------")
	now := time.Now()
	fmt.Println("秒级时间戳:    ", now.Unix())     //1733897761
	fmt.Println("毫秒级时间戳:  ", now.UnixMilli()) //1733897761430
	fmt.Println("微妙级别时间戳: ", now.UnixMicro()) //1733897761430087
	fmt.Println("纳秒级时间戳:   ", now.UnixNano()) //1733897761430087900

}

func countTime() {

	fmt.Println("-------------计算代码耗时(毫秒)------------")
	start := time.Now().UnixMilli()

	var str string
	for i := 0; i < 10*10000; i++ {
		str += "hello" + strconv.Itoa(i)
		//str += "hello" + strconv.FormatInt(int64(i),10)
		//str += "hello" + fmt.Sprintf("%d", i)
	}

	end := time.Now().UnixMilli()
	fmt.Println("毫秒：", end-start)
}
